﻿//---------------------------------------------------------------------
// <copyright file="IDataServiceContextHttpTracker.cs" company="Microsoft">
//      Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
// </copyright>
//---------------------------------------------------------------------

namespace Microsoft.Test.Taupo.Astoria.Contracts.Client
{
    using System;
    using Microsoft.OData.Client;
    using Microsoft.Test.Taupo.Astoria.Contracts.Http;
    using Microsoft.Test.Taupo.Common;

#if !WINDOWS_PHONE
    /// <summary>
    /// Contract for tracking the HTTP request/responses generated by the DataServiceContext
    /// </summary>
    [ImplementationSelector("DataServiceContextHttpTracker", DefaultImplementation = "Default")]
    public interface IDataServiceContextHttpTracker
    {
        /// <summary>
        /// Registers a handler on the given context
        /// </summary>
        /// <param name="context">The context</param>
        /// <param name="handler">The handler for the request/response pairs</param>
        void RegisterHandler(DataServiceContext context, Action<DataServiceContext, HttpRequestData, HttpResponseData> handler);

        /// <summary>
        /// Unregisters a handler for the given context
        /// </summary>
        /// <param name="context">The context</param>
        /// <param name="handler">The handler for the request/response pairs</param>
        /// <param name="shouldCompleteCurrentRequest">A value indicating whether the tracker should try to complete the current request</param>
        void UnregisterHandler(DataServiceContext context, Action<DataServiceContext, HttpRequestData, HttpResponseData> handler, bool shouldCompleteCurrentRequest);

        /// <summary>
        /// Completes the current request if the context is being tracked
        /// </summary>
        /// <param name="context">The context</param>
        /// <returns>True if the context was being tracked, false otherwise</returns>
        bool TryCompleteCurrentRequest(DataServiceContext context);
    }
#endif
}
